package sctu.edu.java.year2016.team04.luoxinghua.Projectmain;

import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * Created by 落叶的思恋 on 2016/6/28.
 */
public class HandleserviceEngineer {
    public static void main(String[] args) throws IOException {
        File filetxt = new File("C:\\TheFourthGroupFile\\ManualService\\", "ManualService.txt ");
        if (!filetxt.exists()) {
            filetxt.createNewFile();
        }
        Scanner scanner = new Scanner(System.in);
        String answre;
        System.out.println("输入”下一条“查看下一个问题");
        while (true) {
            FileInputStream fileInputStream = new FileInputStream(filetxt);
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
            BufferedReader reader = new BufferedReader(inputStreamReader);
            String leave;
            System.out.print("用户的问题是：");
            while ((leave = reader.readLine()) != null) {
                System.out.println(leave);
            }

            System.out.print("你的回答是： ");
            answre = scanner.nextLine();
            if (answre.equals("结束")) {
                filetxt.delete();
                break;
            }
            while (true) {
                Date date = new Date();
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String time = format.format(date);
                answre = time + ":  " + answre;
                FileOutputStream fileOutputStream = new FileOutputStream(filetxt);
                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream);
                BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
                bufferedWriter.write(answre);
                bufferedWriter.flush();
                String ss = scanner.nextLine();
                if (ss.equals("下一条")) break;
            }
            if (answre.equals("结束"))
                break;
        }



    }}
